package com.stray.crawl.expr.psr.jsoup;

import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.stray.crawl.excp.ParseOperationException;
import com.stray.crawl.expr.Express;

public class TextParser extends Express {

	@Override
	protected Object doParse(Object obj, String args) {
		if (obj instanceof Element) {
			Element e = (Element) obj;
			return "own".equals(args) ? e.ownText() : e.text();
		} else if (obj instanceof Elements) {
			return ((Elements) obj).text();
		} else {
			throw new ParseOperationException("Invalid input object for parser. Request: Elements / Element, Input: " + obj.getClass());
		}
	}

}